package pl.umk.mat.fred.unicore.urc.storagemanagement.tree.nodes;

import java.util.ArrayList;
import java.util.List;

import pl.umk.mat.fred.unicore.urc.storagemanagement.unicore.Storage;

import com.intel.gpe.clients.common.requests.GetStoragesRequest;

public class MultiplyCatalogNode extends BelowStorageNode {

	private List<CatalogNode> catalogNodes;
	private boolean opened;
	
	public MultiplyCatalogNode() {
		catalogNodes = new ArrayList<CatalogNode>();
	}
	
	@Override
	public List<Node> getChildren() {
		List<Node> children = new ArrayList<Node>();
		for (CatalogNode cn : catalogNodes) {
			children.addAll(cn.getChildren());
		}
		return children;
	}

	public String getName() {
		if (catalogNodes.isEmpty()) {
			return "empty";
		}
		return catalogNodes.get(0).getName();
	}
	
	public void addCatalog(CatalogNode node) {
		catalogNodes.add(node);
	}
	
	public List<CatalogNode> getCatalogs() {
		return catalogNodes;
	}

	public boolean isOpened() {
		return opened;
	}

	public void setOpened(boolean opened) {
		this.opened = opened;
	}
	
	@Override
	public MultiplyCatalogNode clone(Node nodeParent) {
		MultiplyCatalogNode multiplyCatalogNode = new MultiplyCatalogNode();
		multiplyCatalogNode.setOpened(opened);
		multiplyCatalogNode.setPath(this.getPath());
		multiplyCatalogNode.setParent(nodeParent);
		
		for (CatalogNode cn : catalogNodes) {
			CatalogNode cn2 = cn.clone(nodeParent);
			multiplyCatalogNode.addCatalog(cn2);
		}
		return multiplyCatalogNode;
	}

	@Override
	public RootNode getRootNode() {
		if (catalogNodes.isEmpty()) {
			throw new IllegalStateException("Empty catalog list in MultiplyCatalogNode");
		}
		return catalogNodes.get(0).getRootNode();
	}
	
	
}
